From ed6a62249b7c1f0fcbeb8e67a86a0a291fc3507e Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 28 Nov 2016 21:41:21 +0100 Subject: [PATCH] Use short IDs in git dependencies checkout path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … in order to contribute less to the path length limit on Windows: https://github.com/servo/servo/pull/14397 --- src/cargo/sources/git/source.rs | 7 ++++++- src/cargo/sources/git/utils.rs | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index 321fe4dfc..0587d185f 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -149,8 +149,13 @@ impl<'cfg> Source for GitSource<'cfg> { (self.remote.db_at(&db_path)?, actual_rev.unwrap()) }; + // Don’t use the full hash, + // to contribute less to reaching the path length limit on Windows: + // https://github.com/servo/servo/pull/14397 + let short_id = repo.to_short_id(actual_rev.clone()).unwrap(); + let checkout_path = lock.parent().join("checkouts") - .join(&self.ident).join(actual_rev.to_string()); + .join(&self.ident).join(short_id.as_str()); // Copy the database to the checkout location. After this we could drop // the lock on the database as we no longer needed it, but we leave it diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs index 7452c1dbb..3b3b005f3 100644 --- a/src/cargo/sources/git/utils.rs +++ b/src/cargo/sources/git/utils.rs @@ -19,6 +19,14 @@ impl fmt::Display for GitRevision { } } +pub struct GitShortID(git2::Buf); + +impl GitShortID { + pub fn as_str(&self) -> &str { + self.0.as_str().unwrap() + } +} + /// GitRemote represents a remote repository. It gets cloned into a local /// GitDatabase. #[derive(PartialEq,Clone,Debug)] @@ -215,6 +223,11 @@ impl GitDatabase { Ok(GitRevision(id)) } + pub fn to_short_id(&self, revision: GitRevision) -> CargoResult { + let obj = self.repo.find_object(revision.0, None)?; + Ok(GitShortID(obj.short_id()?)) + } + pub fn has_ref(&self, reference: &str) -> CargoResult<()> { self.repo.revparse_single(reference)?; Ok(()) -- 2.30.2